package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"context"
	"course_srv/course"

	"github.com/zeromicro/go-zero/core/logx"
)

type HandlerOrderListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHandlerOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HandlerOrderListLogic {
	return &HandlerOrderListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HandlerOrderListLogic) HandlerOrderList(req *types.RequestOrderList) (resp *types.Response, err error) {

	order, err := l.svcCtx.CourseSrv.OrderList(l.ctx, &course.OrderListRequest{
		StartTime: req.StartTime,
		EndTime:   req.EndTime,
		OrderSn:   req.OrderSn,
	})
	if err != nil {
		return &types.Response{
			Msg:  "订单列表展示失败",
			Code: "500",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "订单列表展示成功",
		Code: "200",
		Data: map[string]interface{}{
			"order": order,
		},
	}, nil
}
